package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "UpdateUserServlet")
public class UpdateUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");

        //获取表单内容
        String id=request.getParameter("userName");
        String name=request.getParameter("name");
        String pwd=request.getParameter("passWord");
        String sex=request.getParameter("sex");
        String bdate=request.getParameter("birthyear")+"-"+request.getParameter("birthmonth")+"-"+request.getParameter("birthday");
        String tel=request.getParameter("mobile");
        String address=request.getParameter("address");
        String photo=request.getParameter("photo");
        Users users=new Users();
        users.setEu_user_id(id);
        users.setEu_user_name(name);
        users.setEu_password(pwd);
        users.setEu_sex(sex);
        users.setEu_birthday(bdate);
        users.setEu_mobile(tel);
        users.setEu_address(address);
        users.setEu_lj(photo);
        IDAO dao=new UserDao();
        boolean i=false;
        try {
            i=dao.updata(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        if(i){
            request.getRequestDispatcher("manager/manage-result.html").forward(request,response);
        }else {
            PrintWriter pw=response.getWriter();
            pw.print("失败");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
